import request from '@/utils/axios-req'
import settings from '@/settings'

//获取用户信息
export const userInfoReq = () => {
   return  {
        "roles": [],
        "btnPermission": [],
        "permission": false,
        "menuPermission": [],
        "user": {
            "avatar": "",
            "createBy": "admin",
            "createTime": "2023-04-24 02:58:55",
            "delFlag": "0",
            "deptId": 103,
            "email": "13302254693@163.com",
            "loginDate": "2023-10-12 09:49:15",
            "loginIp": "59.41.7.170",
            "nickName": "机智的熊猫哥",
            "password": "$2a$10$b8yUzN0C71sbz.PhNOCgJe.Tu1yWC3RNrTyjSQ8p1W0.aaUXUJ.Ne",
            "phonenumber": "15888888888",
            "remark": "管理员",
            "sex": "1",
            "status": "0",
            "updateBy": "admin",
            "updateTime": "2023-10-12 09:49:15",
            "userId": 0,
            "userName": "admin",
            "userType": "sys_user"
        }
    }
  return new Promise((resolve) => {
    const reqConfig = {
      url: 'getInfo',
      data:{platformId: settings.platformId},
      method: 'get'
    }
    request(reqConfig).then((res) => {
      console.log(res)
      resolve(res?.data)
    })
  })
}

//获取路由信息
export const getRouterReq = () => {
  const datab = [
    {
      alwaysShow: 1,
      component: "",
      createBy: "admin",
      createTime: "2023-05-22 15:53:40",
      icon: "lock",
      isFrame: 1,
      menuId: "1660554505915224065",
      menuName: "Directive",
      menuType: "M",
      metaExtra: '"{}"',
      orderNum: 10,
      parentId: 0,
      path: "/directive",
      perms: "",
      platformId: 1,
      redirect: "",
      remark: "",
      routeName: "Directive",
      status: "0",
      updateBy: "test",
      updateTime: "2023-05-23 09:28:36",
      visible: "0",
    },
    {
      alwaysShow: 1,
      children: undefined,
      component: "directive/copy.vue",
      createBy: "admin",
      createTime: "2023-05-22 15:54:03",
      icon: "email",
      isFrame: 1,
      menuId: "1660554600979124226",
      menuName: "物料信息",
      menuType: "C",
      metaExtra: '"{}"',
      orderNum: 10,
      parentId: "1660554505915224065",
      path: "/copy",
      perms: "copy",
      platformId: 1,
      redirect: "",
      remark: "",
      routeName: "copy",
      status: "0",
      updateBy: "admin",
      updateTime: "2023-05-22 16:09:27",
      visible: "1",
    },
    {
      alwaysShow: 1,
      children: undefined,
      component: "directive/debounce.vue",
      createBy: "admin",
      createTime: "2023-05-22 15:54:29",
      icon: "peoples",
      isFrame: 1,
      menuId: "1660554711469674497",
      menuName: "物料管理",
      menuType: "C",
      metaExtra: '"{}"',
      orderNum: 10,
      parentId: "1660554505915224065",
      path: "debounce",
      perms: "debounce",
      platformId: 1,
      redirect: "",
      remark: "",
      routeName: "debounce",
      status: "0",
      updateBy: "admin",
      updateTime: "2023-05-22 15:54:29",
      visible: "0",
    },
    {
      alwaysShow: 1,
      children: undefined,
      component: "directive/watermark.vue",
      createBy: "admin",
      createTime: "2023-05-22 15:55:41",
      icon: "job",
      isFrame: 1,
      menuId: "1660555010905231361",
      menuName: "供应商管理",
      menuType: "C",
      metaExtra: '"{}"',
      orderNum: 10,
      parentId: "1660554505915224065",
      path: "watermark",
      perms: "watermark",
      platformId: 1,
      redirect: "",
      remark: "",
      routeName: "watermark",
      status: "0",
      updateBy: "admin",
      updateTime: "2023-05-22 15:55:41",
      visible: "0",
    },
    {
      alwaysShow: 1,
      children: undefined,
      component: "directive/orderDetail.vue",
      createBy: "admin",
      createTime: "2023-05-22 15:55:41",
      icon: "job",
      isFrame: 1,
      menuId: "1660554867850104834",
      menuName: "订单明细",
      menuType: "C",
      metaExtra: '"{}"',
      orderNum: 10,
      parentId: "1660554505915224065",
      path: "orderDetail",
      perms: "orderDetail",
      platformId: 1,
      redirect: "",
      remark: "",
      routeName: "orderDetail",
      status: "0",
      updateBy: "admin",
      updateTime: "2023-05-22 15:55:41",
      visible: "1",
    },
    {
      alwaysShow: 1,
      children: undefined,
      component: "directive/orderAdd.vue",
      createBy: "admin",
      createTime: "2023-05-22 15:55:41",
      icon: "job",
      isFrame: 1,
      menuId: "1660554867850104834",
      menuName: "添加订单",
      menuType: "C",
      metaExtra: '"{}"',
      orderNum: 10,
      parentId: "1660554505915224065",
      path: "orderAdd",
      perms: "orderAdd",
      platformId: 1,
      redirect: "",
      remark: "",
      routeName: "orderAdd",
      status: "0",
      updateBy: "admin",
      updateTime: "2023-05-22 15:55:41",
      visible: "1",
    },
    {
      alwaysShow: 1,
      children: undefined,
      component: "directive/orderPage.vue",
      createBy: "admin",
      createTime: "2023-05-22 15:55:41",
      icon: "job",
      isFrame: 1,
      menuId: "1660554867850104834",
      menuName: "订单管理",
      menuType: "C",
      metaExtra: '"{}"',
      orderNum: 10,
      parentId: "1660554505915224065",
      path: "orderPage",
      perms: "orderPage",
      platformId: 1,
      redirect: "",
      remark: "",
      routeName: "orderPage",
      status: "0",
      updateBy: "admin",
      updateTime: "2023-05-22 15:55:41",
      visible: "0",
    },
    {
      alwaysShow: 1,
      children: undefined,
      component: "directive/longpress.vue",
      createBy: "admin",
      createTime: "2023-05-22 15:55:07",
      icon: "github",
      isFrame: 1,
      menuId: "1660554867850104834",
      menuName: "供应商信息",
      menuType: "C",
      metaExtra: '"{}"',
      orderNum: 10,
      parentId: "1660554505915224065",
      path: "longpress",
      perms: "longpress",
      platformId: 1,
      redirect: "",
      remark: "",
      routeName: "longpress",
      status: "0",
      updateBy: "admin",
      updateTime: "2023-05-22 15:55:07",
      visible: "1",
    }
  ]
  return datab
  return new Promise((resolve) => {
    const reqConfig = {
      url: 'getMenu',
      params: { platformId: settings.platformId },
      reqLoading: false,
      method: 'get'
    }
    request(reqConfig).then(({ data }) => {
      // console.log(data,11)
      // data.forEach((item,index) => {
      //   if(item.path == "addMaterial"){
      //     data[index].path = "/addMaterial"
      //     console.log(item,2222)
      //   }
      // });
      
      console.log(data,2)
      resolve(data)
    })
  })
}

//登录
export const loginReq = (subForm) => {
  return request({
    url: 'login',
    data: subForm,
    method: 'post',
    isNotTipErrorMsg: true
  })
}

// 注册方法
export const register = (data) => {
  return request({
    url: 'register',
    method: 'post',
    params:data
  })
}

//退出登录
export const loginOutReq = () => {
  return request({
    url: 'logout',
    method: 'post'
  })
}

//获取验证码
export const getCodeImg = () => {
  return request({
    url: '/captchaImage',
    headers: {
      isToken: false
    },
    data:{
      width:100,
      height:50
    },
    method: 'get'
  })
}

// 用户状态修改
export function changeUserStatus(userId, status) {
  const data = {
    userId,
    status
  }
  return request({
    url: '/system/user/changeStatus',
    method: 'put',
    data
  })
}
//查询列表
export const listReq = (query) => {
  return request({
    url: '/system/user/list',
    method: 'post',
    data: query||{}
  })
}

//删除
export const deleteReq = (id) => {
  return request({
    url: `/system/user/${id}`,
    method: 'delete'
  })
}

//批量删除
export const multiDeleteReq = (id) => {
  return request({
    url: `/system/user/${id}`,
    method: 'delete'
  })
}

//导入
export const importReq = (updateSupport, data) => {
  return request({
    url: `/system/user/importData?updateSupport=${updateSupport}`,
    method: 'post',
    data
  })
}

//导出
export const exportReq = (reqConfig) => {
  return request({
    url: `/system/user/export`,
    method: 'post',
    responseType: 'blob',
    params: Object.assign(reqConfig)
  })
}

//模板下载
export const downloadTemplateReq = () => {
  return request({
    url: `system/user/importTemplate`,
    method: 'post'
  })
}
// 新增和编辑接口

//新增
export const addUser = (data) => {
  return request({
    url: `/system/user`,
    data,
    method: 'post'
  })
}
//更新
export const updateUser = (data) => {
  return request({
    url: `/system/user`,
    data,
    method: 'put'
  })
}
//详情
export const getUser = (id) => {
  return request({
    url: `/system/user/${id}`,
    method: 'get'
  })
}

//详情
export const getUserInfo = () => {
  return request({
    url: `/system/user`,
    method: 'get'
  })
}

// 保存授权角色
export function updateAuthRole(data) {
  return request({
    url: '/system/user/authRole',
    method: 'put',
    params: data
  })
}

// 查询部门下拉树结构
export function deptTreeSelect() {
  return request({
    url: '/system/user/deptTree',
    method: 'get'
  })
}

// 查询授权角色
export function getAuthRole(userId) {
  return request({
    url: `/system/user/authRole/${userId}`,
    method: 'get'
  })
}

// 用户密码重置
export function resetUserPwd(userId, password) {
  const data = {
    userId,
    password
  }
  return request({
    url: '/system/user/resetPwd',
    method: 'put',
    data
  })
}
